package com.gdust.gkyx.activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gdust.gkyx.activity.service.CouponInfoService;
import com.gdust.gkyx.common.result.Result;
import com.gdust.gkyx.model.activity.CouponInfo;
import com.gdust.gkyx.vo.activity.CouponRuleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ClassName: CouponInfoController
 * Package: com.gdust.gkyx.activity.controller
 * Description:优惠券信息 前端控制器
 *
 * 参考前端：src >api>activity>Js couponInfo.js编写接口
 *
 * @Author syun
 * @Create 2025/1/26 16:10
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/activity/couponInfo")
//@CrossOrigin
public class CouponInfoController {

    @Autowired
    private CouponInfoService couponInfoService;

    /**
     * //1 优惠卷分页查询
     * //    url: `${api_name}/${page}/${limit}`,
     * //    method: 'get'
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit) {
        IPage<CouponInfo> pageModel =
                couponInfoService.selectPageCouponInfo(page,limit);
        return Result.ok(pageModel);
    }

    /**
     * //2 添加优惠卷
     * //    url: `${api_name}/save`,
     * //    method: 'post',
     * //    data: role
     * @param couponInfo
     * @return
     */
    @ApiOperation(value = "新增优惠券")
    @PostMapping("save")
    public Result save(@RequestBody CouponInfo couponInfo) {
        couponInfoService.save(couponInfo);
        return Result.ok(null);
    }

    /**
     * //3 根据id查询优惠卷
     * //    url: `${api_name}/get/${id}`,
     * //    method: 'get'
     * @param id
     * @return
     */
    @ApiOperation(value = "获取优惠券")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        CouponInfo couponInfo = couponInfoService.getCouponInfo(id);
        return Result.ok(couponInfo);
    }

    /**
     * //4 根据优惠卷id查询规则数据
     * //    url: `${api_name}/findCouponRuleList/${id}`,
     * //    method: 'get'
     * @param id
     * @return
     */
    @ApiOperation(value = "获取优惠券信息")
    @GetMapping("findCouponRuleList/{id}")
    public Result findCouponRuleList(@PathVariable Long id) {
        Map<String,Object> map =
                couponInfoService.findCouponRuleList(id);
        return Result.ok(map);
    }

    /**
     * //5 添加优惠卷规则数据
     * //    url: `${api_name}/saveCouponRule`,
     * //    method: 'post',
     * //    data: rule
     * @param couponRuleVo
     * @return
     */
    @ApiOperation(value = "新增活动")
    @PostMapping("saveCouponRule")
    public Result saveCouponRule(@RequestBody CouponRuleVo couponRuleVo) {
        couponInfoService.saveCouponRule(couponRuleVo);
        return Result.ok(null);
    }

    /**
     * 修改优惠券
     * @param couponInfo
     * @return
     */
    @ApiOperation(value = "修改优惠券")
    @PutMapping("update")
    public Result updateById(@RequestBody CouponInfo couponInfo) {
        couponInfoService.updateById(couponInfo);
        return Result.ok(null);
    }

    /**
     * 删除优惠券
     * @param id
     * @return
     */
    @ApiOperation(value = "删除优惠券")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable String id) {
        couponInfoService.removeById(id);
        return Result.ok(null);
    }

    /**
     * 根据id列表删除优惠券
     * @param idList
     * @return
     */
    @ApiOperation(value="根据id列表删除优惠券")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<String> idList){
        couponInfoService.removeByIds(idList);
        return Result.ok(null);
    }



}
